class Circle { private int R; private final static double PI=3.14 ; PI=3.1407; }
6: error: <identifier> expected PI=3.1407;
class Circle { private int R; public Circle(int n) { r=n; } public void area() { final double PI=3.14; double a=PI*R*R; System.out.println("Area is "+a); PI=3.1407; } }
13: error: cannot assign a value to final variable PI PI=3.1407;
class Password { private String userid,pwd; public void setData(String userid,String pwd) { this.userid=userid ; this.pwd=pwd; } Public final boolean verify(String ud,String pd) { if(userid.equals(ud)&&pwd.equals(pd)) return true; else return false; } } class HackedPassword extends Password { public boolean verify(String ud,String pd) { return true; } }
error: verify(String,String) in HackedPassword cannot override verify(String,String) in Password public boolean verify(String ud,String pd) ^ overridden method is final
final class Password { private String userid,pwd; public void setData(String userid,String pwd) { this.userid=userid; this.pwd=pwd; } public boolean verify(String ud,String pd) { if(userid.equals(ud)&&pwd.equals(pd)) return true; else return false; } } class HackedPassword extends Password { public boolean verify(String ud,String pd) { return true; } }
error: cannot inherit from final Password class HackedPassword extends Password ^